package my_stream;

import java.util.*;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collectors;

public class demo3 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"西红柿", "土豆", "牛腩", "排骨", "米粉", "米饭");

        String[] str = list.stream().toArray(value -> new String[value]);

        //System.out.println(Arrays.toString(str));

        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"西红柿-素-9", "牛肉-荤-15",
                "白菜-素-9", "猪肉-荤-13", "土豆-素-9");

        Map<String, Integer> map1 = list1.stream()
                .filter(s->"荤".equals(s.split("-")[1]))
                .collect(Collectors.toMap(new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return s.split("-")[0];
                    }
                }, new Function<String, Integer>() {
                    @Override
                    public Integer apply(String s) {
                        return Integer.parseInt(s.split("-")[2]);
                    }
                }));

        System.out.println(map1);

    }
}
